package com.shchuangzhi.smartguard;

import android.content.Context;
import android.content.SharedPreferences;

import com.shchuangzhi.smartguard.core.Consts;

/**
 * Created by j_hu on 11/3/17.
 */

public class SharedPref {

    private Context context;
    private SharedPreferences pref;
    private static final SharedPref shared = new SharedPref();

    public void init(Context context) {
        this.context = context;
        this.pref = context.getSharedPreferences(Consts.APP_FULL_NAME, Context.MODE_PRIVATE);
    }

    public String getLocalServiceURL() {
        String localServiceUrl = "";
        if (pref != null) {
            localServiceUrl = pref.getString(context.getString(R.string.host_preference), "");
        }
        return localServiceUrl;
    }

    public String getRemoteServiceURL() {
        String remoteServiceUrl = "";
        if (pref != null) {
            remoteServiceUrl = pref.getString(context.getString(R.string.network_preference), "");
        }
        return remoteServiceUrl;
    }

    public String getTerminalName() {
        String terminalName = "";
        if (pref != null) {
            terminalName = pref.getString(context.getString(R.string.terminal_name_preference), "");
        }
        return terminalName;
    }

    public boolean getMachineSwitchValue() {
        boolean switchValue = true;
        if (pref != null) {
            switchValue = pref.getBoolean(context.getString(R.string.machine_mode_preference), true);
        }
        return switchValue;
    }

    public SharedPreferences getPreferences() {
        return pref;
    }

    public static final SharedPref getInstance() {
        return shared;
    }
}
